
#encoding:utf-8
import os
import subprocess
script_dir = os.path.dirname(os.path.abspath(__file__)) #by robot
os.chdir(script_dir)
stop_head='''

<!DOCTYPE html>
<html>

<head>
    <title>888666444's Music Webside</title>
</head>

<body style="margin: 0;padding: 0;font-family: 'Courier New', Courier, monospace;">
    <div style="height: 60px;padding: 15px;">
        <div style="float:left"><img src="./../../index.png" style="width: 100px;"></div>
        <div style="float:right">
            <p style="color:gray;font-size: small;">888666444's Music Website</p>
        </div>
    </div>
    <hr>
    <div style="padding: 15px;min-height: 600px;text-align: center;">
        <h1 style="font-size:60px;">Stop Service</h1>

    
'''
stop_foot='''
</div>
    <div>
        <footer
            style="background-color:#646464;text-align: center;height: 100px;margin-top: 62px;padding:20px;bottom:0;position: relative">
            <p style="color:white">888666444's Music Website</p>
        </footer>
    </div>
</body>

</html>

'''
head = '''
<!DOCTYPE html>
<html>

<head>
    <title>888666444's Music Webside</title>
</head>

<body style="margin: 0;padding: 0;font-family: 'Courier New', Courier, monospace;">
    <div style="height: 60px;padding: 15px;">
        <div style="float:left"><img src="./../../index.png" style="width: 100px;"></div>
        <div style="float:right">
            <p style="color:gray;font-size: small;">888666444's Music Website</p>
        </div>
    </div>
    <hr>
    <p>Music List:</p>
    <div style="padding: 15px;min-height: 1200px;">
        <div style="background-color: #e2e2e2;">
            
        
'''
foot = '''
		</div>
    </div>
    <div>
        <footer
            style="background-color:#646464;text-align: center;height: 100px;margin-top: 62px;padding:20px;bottom:0;position: relative">
            <p style="color:white">888666444's Music Website</p>
        </footer>
    </div>
</body>

</html>
'''
file = open("index.html","w")
file.write(head)
lsdata=[]
try:
	lsdata = os.listdir("./music")
except FileNotFoundError:
	os.mkdir("./music")
for data in lsdata:
	musicpath = "./music/"+data+"/music.mp3"
	#print(musicpath)
	#print(data)
	_str = '''<div style="height: 70px;width: 100%;">
                <div
                    style="float:left;width:200px;height:70px;text-align:center;display: table-cell;vertical-align: middle;">
                    <h3 style="color: black;">'''+data+'''</h3>
                </div>
                <div style="float:right;width: max-content;vertical-align: middle;">
                    <audio controls
                        style="float:left;outline: none;background-color: #e2e2e2;min-width: 400px;max-width: 1200px;width: max-content;height: 60px;">
                        <source src="'''+musicpath+'''" type="audio/mpeg">
                    </audio>
                </div>
            </div>
            <hr>'''
	file.write(_str)
file.write(foot)
file.close()
if(os.access("stop.txt",os.F_OK)):
    reason = open("stop.txt").read()
    with open("./index.html","w") as file:
        stop_str=str(stop_head)+'''<h3 style="font-size:25px;">'''+str(reason)+'''</h3>
        <hr style="border: 1px dashed black;">
        '''+'''<h3 style="color:grey;font-size:17px;">'''+os.path.abspath("./index.html")+'''</h3>'''+stop_foot
        file.write(stop_str)
    